home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 October: Mac OS SDK / Dev.CD Oct 97 SDK2.toast / Development Kits (Disc 2) / ScriptX / Code Samples / autofind / source / axis.sx < prev    next >
Encoding:
Text File  |  1996-05-21  |  3.7 KB  |  135 lines  |  [TEXT/ttxt]

  1. --<<<
  2. -- Filename: 
  3. --     axis.sx
  4.  
  5. -- Other Files Required:
  6. --     none
  7.  
  8. -- Purpose:  
  9. --     axis.sx defines abstract classes for building the axes of the grapher tool.
  10.  
  11. -- Specialized Classes:  
  12. --     Axis
  13.  
  14. -- Instructions to User: 
  15. --     The axis class is a group of presenters that define the length
  16. --     of the axis, the minimum and maximum value labels, and the axis label.  
  17.  
  18. -- Author:
  19. --     Dionn Stewart.  Revised by Ray Davis.
  20.  
  21. --  The axis class associates an abstract axis, the minimum and maximum value labels,
  22. --  the axis label, and the current property of the axis.  That is, it collects
  23. --    those elements which will be changed when the property graphed on the axis
  24. --    changes.
  25. --    Formats and placements of the labels are left up to the grapher.
  26. --    The axis must be presented by a grapher object.
  27. in module Autofinder
  28.  
  29. class Axis (GroupSpace)
  30. instance variables
  31.     origin            -- origin of axis in pixel offset
  32.     length             -- length of axis, used to determine pixel/value scale
  33.     minLabel        -- presenter to display the minimum value
  34.     maxLabel        -- presenter to display the maximum value
  35.     axisLabel        -- an AxisLabel that must provide Actuator capabilities
  36.     property        -- an AxisProperty that the axis will represent
  37.     scale            -- scale in pixels for the current property
  38. end
  39.  
  40. method init self {class Axis} #rest args #key \
  41.     origin:(0) \
  42.     length:(undefined) \
  43.     minLabel:(new TextPresenter boundary:(new Rect x2:50 y2:18) target:"" \
  44.             fill:whiteBrush stroke:blackBrush) \
  45.     maxLabel:(new TextPresenter boundary:(new Rect x2:50 y2:18) target:"" \
  46.         fill:whiteBrush stroke:blackBrush) \
  47.     axLabel: ->
  48. (
  49.     apply nextMethod self args
  50.     self.axisLabel := axLabel
  51.     self.origin:= origin
  52.     self.length:= length
  53.     self.minLabel := minLabel
  54.     self.maxLabel := maxLabel
  55.     self
  56. )
  57.  
  58. method afterInit self {class Axis} #rest args #key \
  59.     property:(undefined) ->
  60. (
  61.     local minLabel, maxLabel, labelFont
  62.     
  63.     apply nextMethod self args
  64.  
  65.     -- set text attributes for min and max labels
  66.     minLabel := self.minLabel
  67.     maxLabel := self.maxLabel
  68.     labelFont := new platformfont name:"Palatino"
  69.  
  70.     setDefaultAttr minLabel @font labelFont
  71.     setDefaultAttr minLabel @size 10
  72.     setDefaultAttr minLabel @alignment @center
  73.     setDefaultAttr minLabel @leading 12
  74.  
  75.     setDefaultAttr maxLabel @font labelFont
  76.     setDefaultAttr maxLabel @size 10
  77.     setDefaultAttr maxLabel @alignment @center
  78.     setDefaultAttr maxLabel @leading 12
  79.  
  80.     changeProperty self property
  81.  
  82.     -- Bundle the parts of the axis together
  83.     append self minLabel
  84.     append self maxLabel
  85.     append self self.axisLabel
  86.  
  87.     -- Make the actuator controller for the axis label
  88.     local ac:= new actuatorController space:self
  89.     append ac self.axisLabel
  90.     self
  91. )
  92.  
  93. -- Changing the property of the axis, so update the presenters
  94. -- and re-graph the objects currently shown.
  95. -- This is usually called by the Grapher's propertyMenu.
  96. method changeProperty self {class Axis} prop ->
  97. (
  98.     self.property := prop
  99.     if prop <> undefined do
  100.     (
  101.         setLabels self prop
  102.         local val := prop.maxValue - prop.minValue
  103.         if (val <> 0) then
  104.             self.scale := self.length/val
  105.         else
  106.             self.scale := 0
  107.     )
  108.  
  109.     -- Let our presenter know that graphable objects must be rearranged
  110.     -- on the graph
  111.     if self.presentedBy <> undefined do
  112.         refreshGraph self.presentedBy
  113. )
  114.  
  115. -- Update the labels to present the new property
  116. method setLabels self {class Axis} prop ->
  117. (
  118.     self.minLabel.target:= prop.minTarget
  119.     self.maxLabel.target:= prop.maxTarget
  120.     self.axisLabel.target:= prop.axisTarget
  121.     prop
  122. )
  123.  
  124. -- This method returns a pixel offset that corresponds to the property
  125. -- value where prop is the graph property and val is the value to 
  126. -- be translated
  127. method scaleValue self {class Axis} prop val ->
  128. (
  129.     local diff:= max 0 (val - prop.minValue)
  130.     (diff * self.scale) as integer 
  131. )
  132.  
  133. "Compiled axis.sx"
  134. -->>>
  135.